package cn.wolfcode.luowowo.website.web.advice;

import cn.wolfcode.luowowo.common.util.AjaxResult;
import cn.wolfcode.luowowo.common.util.LogicException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 统一异常处理
 */
@ControllerAdvice
public class AdviceCommonExceptionHandler {

    /**
     * 处理登录出现的异常
     * @param e
     * @return
     */
    @ExceptionHandler(LogicException.class)
    @ResponseBody
    public Object logicException(Exception e) {
        e.printStackTrace();
        return new AjaxResult(false, e.getMessage());
    }

    /**
     * 处理系统出现的异常
     * @param e
     * @return
     */
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Object otherException(Exception e) {
        e.printStackTrace();
        return new AjaxResult(false,"网络出现异常,请联系管理员");
    }

}
